<template>
  <div>
    <!-- 固化信息有效性检测 -->
    <div v-if="item.dId == '1111' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 固化信息有效性检测</p>
          <p v-if="phase == '0'||phase == '4'">检测对象: 归档-电子文件</p>
          <p v-if="phase == '1'">检测对象: 移交-电子档案</p>
          <p v-if="phase == '2'">检测对象: 长期-电子档案</p>
        </template>
        <el-checkbox-group v-model="selected" :disabled="item.isPass == '1'" @change="getSelected" >
          <el-checkbox v-for="dict in dict.type.GHXX" :value="dict.value" :key="dict.value" :label="dict.value">{{ dict.label }}</el-checkbox>
        </el-checkbox-group>
      </el-collapse-item>
    </div>

    <!-- 元数据项数据长度检测 -->
    <div v-if="item.dId == '1121' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 元数据项数据长度检测</p>
          <p>检测对象: 元数据</p>
        </template>
        <el-tabs v-model="activeLength" style="width: 90%" @tab-click="tabClick">
          <el-tab-pane label="卷层" name="first" v-if="subStr == 'V' || subStr == 'X'">
            <el-checkbox-group v-model="firstSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in folderOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input-number :min='1' v-model="firstInput[checkboxItem.id]" :disabled="!checkboxItem.editable" placeholder="输入符合的长度,例如100" @change="getChangeFirstInput"></el-input-number>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="folderCurrentPage" :page-size="folderPageSize" :total="folderTotal" @current-change="handleFolderPageChange"></el-pagination>
          </el-tab-pane>
          <el-tab-pane label="件层" name="second">
            <el-checkbox-group v-model="secondSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in fileOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input-number :min='1' v-model="secondInput[checkboxItem.id]" :disabled="!checkboxItem.editable" placeholder="输入符合的长度,例如100" @change="getChangeSecondInput"></el-input-number>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="fileCurrentPage" :page-size="filePageSize" :total="fileTotal" @current-change="handleFilePageChange"></el-pagination>
          </el-tab-pane>
        </el-tabs>
      </el-collapse-item>
    </div>

    <!-- 元数据项数据类型、格式检测 -->
    <div v-if="item.dId == '1122' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 元数据项数据类型、格式检测</p>
          <p>检测对象: 元数据</p>
        </template>
        <el-tabs v-model="activeLength" style="width: 90%">
          <el-tab-pane label="卷层" name="first" v-if="subStr == 'V' || subStr == 'X'">
            <el-checkbox-group v-model="firstSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in folderOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem,index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-select placeholder="请选择" v-model="firstSelected[checkboxItem.id]" :disabled="!checkboxItem.editable" @change="getJuanSelected">
                    <el-option v-for="dict in dict.type.SJLX" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
                  </el-select>
                  <el-select placeholder="请选择" v-model="secondSelected[checkboxItem.id]" :disabled="!checkboxItem.editable" @change="getJuanSelected">
                    <el-option v-for="dict in dict.type.GSJC" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
                  </el-select>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="folderCurrentPage" :page-size="folderPageSize" :total="folderTotal" @current-change="handleFolderPageChange"></el-pagination>
          </el-tab-pane>
          <el-tab-pane label="件层" name="second">
            <el-checkbox-group v-model="secondSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in fileOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem,index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-select placeholder="请选择" v-model="thirdSelected[checkboxItem.id]" :disabled="!checkboxItem.editable" @change="getJianSelected">
                    <el-option v-for="dict in dict.type.SJLX" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
                  </el-select>
                  <el-select placeholder="请选择" v-model="fourthSelected[checkboxItem.id]" :disabled="!checkboxItem.editable" @change="getJianSelected">
                    <el-option v-for="dict in dict.type.GSJC" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
                  </el-select>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="fileCurrentPage" :page-size="filePageSize" :total="fileTotal" @current-change="handleFilePageChange"></el-pagination>
          </el-tab-pane>
        </el-tabs>
      </el-collapse-item>
    </div>

    <!-- 设定值域的元数据项值域符合度检测 -->
    <div v-if="item.dId == '1123' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 设定值域的元数据项值域符合度检测</p>
          <p>检测对象: 元数据</p>
        </template>
        <el-tabs v-model="activeLength" style="width: 90%">
          <el-tab-pane label="卷层" name="first" v-if="subStr == 'V' || subStr == 'X'">
            <el-checkbox-group v-model="firstSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in folderOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input v-model="firstInput[checkboxItem.id]" :disabled="!checkboxItem.editable" placeholder="输入值域,例如案卷,文书" @change="getChangeFirstInput"></el-input>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="folderCurrentPage" :page-size="folderPageSize" :total="folderTotal" @current-change="handleFolderPageChange"></el-pagination>
          </el-tab-pane>
          <el-tab-pane label="件层" name="second">
            <el-checkbox-group v-model="secondSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in fileOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input v-model="secondInput[checkboxItem.id]" :disabled="!checkboxItem.editable" placeholder="输入值域,例如案卷,文书" @change="getChangeSecondInput"></el-input>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="fileCurrentPage" :page-size="filePageSize" :total="fileTotal" @current-change="handleFilePageChange"></el-pagination>
          </el-tab-pane>
        </el-tabs>
      </el-collapse-item>
    </div>

    <!-- 元数据项数据值合理性检测 -->
    <div v-if="item.dId == '1124' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 元数据项数据值合理性检测</p>
          <p>检测对象: 元数据</p>
        </template>
        <el-tabs v-model="activeLength" style="width: 90%">
          <el-tab-pane label="卷层" name="first" v-if="subStr == 'V' || subStr == 'X'">
            <el-checkbox-group v-model="firstSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in folderOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input v-model="firstInput[checkboxItem.id]" :disabled="!checkboxItem.editable" placeholder="输入值域,例如案卷,文书" @change="getChangeFirstInput"></el-input>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="folderCurrentPage" :page-size="folderPageSize" :total="folderTotal" @current-change="handleFolderPageChange"></el-pagination>
          </el-tab-pane>
          <el-tab-pane label="件层" name="second">
            <el-checkbox-group v-model="secondSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in fileOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input v-model="secondInput[checkboxItem.id]" :disabled="!checkboxItem.editable" placeholder="输入值域,例如案卷,文书" @change="getChangeSecondInput"></el-input>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="fileCurrentPage" :page-size="filePageSize" :total="fileTotal" @current-change="handleFilePageChange"></el-pagination>
          </el-tab-pane>
        </el-tabs>
      </el-collapse-item>
    </div>

    <!-- 元数据项数据包含特殊字符检测 -->
    <div v-if="item.dId == '1125' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 元数据项数据包含特殊字符检测</p>
          <p>检测对象: 元数据</p>
        </template>
        <el-tabs v-model="activeLength" style="width: 90%">
          <el-tab-pane label="卷层" name="first" v-if="subStr == 'V' || subStr == 'X'">
            <el-checkbox-group v-model="firstSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in folderOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input v-model="firstInput[checkboxItem.id]" :disabled="!checkboxItem.editable" placeholder="用,分隔" @change="getChangeFirstInput"></el-input>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="folderCurrentPage" :page-size="folderPageSize" :total="folderTotal" @current-change="handleFolderPageChange"></el-pagination>
          </el-tab-pane>
          <el-tab-pane label="件层" name="second">
            <el-checkbox-group v-model="secondSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in fileOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input v-model="secondInput[checkboxItem.id]" :disabled="!checkboxItem.editable" placeholder="用,分隔" @change="getChangeSecondInput"></el-input>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="fileCurrentPage" :page-size="filePageSize" :total="fileTotal" @current-change="handleFilePageChange"></el-pagination>
          </el-tab-pane>
        </el-tabs>
      </el-collapse-item>
    </div>

    <!-- 档号规范性检测 -->
    <div v-if="item.dId == '1126' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 档号规范性检测</p>
          <p>检测对象: 归档号、档号</p>
        </template>
        <el-tabs v-model="activeLength" style="width: 90%">
          <el-tab-pane label="卷层" name="first" v-if="subStr == 'V' || subStr == 'X'">
            <el-checkbox-group v-model="firstSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in folderOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item, checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input v-model="firstInput[checkboxItem.id]" :disabled="true" placeholder="多个用;分隔" @input="getChangeFirstInput"></el-input>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="folderCurrentPage" :page-size="folderPageSize" :total="folderTotal" @current-change="handleFolderPageChange"></el-pagination>
          </el-tab-pane>
          <el-tab-pane label="件层" name="second">
            <el-checkbox-group v-model="secondSelect" :disabled="item.isPass == '1'">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in fileOption" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item, checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                  <el-input v-model="secondInput[checkboxItem.id]" :disabled="true" placeholder="多个用;分隔" @input="getChangeSecondInput"></el-input>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="fileCurrentPage" :page-size="filePageSize" :total="fileTotal" @current-change="handleFilePageChange"></el-pagination>
          </el-tab-pane>
        </el-tabs>
      </el-collapse-item>
    </div>

    <!-- 元数据项数据重复性检测 -->
    <div v-if="item.dId == '1127' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 元数据项数据重复性检测</p>
          <p>检测对象: 用户自定义重复性检测元数据项</p>
        </template>
        <el-tabs v-model="activeLength" style="width: 90%">
          <el-tab-pane label="卷层" name="first" v-if="subStr == 'V' || subStr == 'X'">
            <el-checkbox-group v-model="folderSelected" :disabled="item.isPass == '1'" @change="getFolderSelected">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in folderRepeat" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="folderCurrentPage" :page-size="folderPageSize" :total="folderTotal" @current-change="handleFolderPageChange"></el-pagination>
          </el-tab-pane>
          <el-tab-pane label="件层" name="second">
            <el-checkbox-group v-model="fileSelected" :disabled="item.isPass == '1'" @change="getFileSelected">
              <div style="display: flex; flex-wrap: wrap;">
                <div v-for="(checkboxItem,index) in fileRepeat" class="checkBox" :key="index">
                  <el-checkbox :value="checkboxItem.id" :key="checkboxItem.id" :label="checkboxItem.id" @change="handleChange(item,checkboxItem, index)">{{ checkboxItem.label }}</el-checkbox>
                </div>
              </div>
            </el-checkbox-group>
            <el-pagination :current-page="fileCurrentPage" :page-size="filePageSize" :total="fileTotal" @current-change="handleFilePageChange"></el-pagination>
          </el-tab-pane>
        </el-tabs>
      </el-collapse-item>
    </div>

    <!-- 元数据与档案馆要求的一致性检测 -->
    <div v-if="item.dId == '1128' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 元数据与档案馆要求的一致性检测</p>
          <p>检测对象: 全宗号、目录号、分类号</p>
        </template>
        <div style="padding-left: 3%;">
          依据DA/T 13和用户自定义的全宗号、目录号、分类号编制规则进行检测: <br>
          a)对数据库中全宗号、目录号、分类号的编制规范性进行检测； <br>
          b)对移交信息包中全宗号、目录号、分类号的编制规范性进行检测 <br>
          <el-checkbox-group v-model="selected" :disabled="item.isPass == '1'" @change="getSelected">
            <el-checkbox v-for="dict in dict.type.YQYZXJC" :value="dict.value" :key="dict.value" :label="dict.value">{{ dict.label }}</el-checkbox>
          </el-checkbox-group>
        </div>
      </el-collapse-item>
    </div>

    <!-- 内容数据的电子属性一致性检测 -->
    <div v-if="item.dId == '1131' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 内容数据的电子属性一致性检测</p>
          <p>检测对象: 内容数据</p>
        </template>
        <div style="padding-left: 3%;">
          捕获电子文件/电子档案内容数据的电子属性信息(包括计算机文件名、文件大小、文件格式、创建时间等),与电子属性信息中记录的数据进行比对 <br>
          <el-checkbox-group v-model="selected" :disabled="item.isPass == '1'" @change="getSelected">
            <el-checkbox v-for="dict in dict.type.YZXJC" :value="dict.value" :key="dict.value" :label="dict.value">{{ dict.label }}</el-checkbox>
          </el-checkbox-group>
        </div>
      </el-collapse-item>
    </div>

    <!-- 元数据是否关联内容数据检测 -->
    <div v-if="item.dId == '1141' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 元数据是否关联内容数据检测</p>
          <p>检测对象: 内容数据</p>
        </template>
        <div style="padding-left: 3%;">
          <el-radio @change="getRadio" v-model="radio" :label="'1'">依据元数据中记录的文件存储路径，检测电子文件/电子档案内容数据是否存在</el-radio>
        </div>
      </el-collapse-item>
    </div>

    <!-- 说明文件和目录文件规范性检测 -->
    <div v-if="item.dId == '1151' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 说明文件和目录文件规范性检测</p>
          <p>检测对象: 说明文件、目录文件</p>
        </template>
        <div style="padding-left: 3%;">
          <el-radio @change="getRadio" v-model="radio" :label="'1'">依据国家有关规定,检测说明文件和目录文件信息组织结构是否符合规范</el-radio>
        </div>
      </el-collapse-item>
    </div>

    <!-- 信息包目录结构规范性检测 -->
    <div v-if="item.dId == '1152' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 信息包目录结构规范性检测</p>
          <p>检测对象: 文件夹名称；目录结构</p>
        </template>
        <div style="padding-left: 3%;">
          <el-radio @change="getRadio" v-model="radio" :label="'1'">检测归档信息包内的文件夹结构是否符合规范</el-radio>
        </div>
      </el-collapse-item>
    </div>

    <!-- 信息包一致性检测 -->
    <div v-if="item.dId == '1153' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="(item.isPass == '1') || Packet">
        <template slot="title">
          <p style="width: 60%">检测项目: 信息包一致性检测</p>
          <p>检测对象: 信息包</p>
        </template>
        <div style="padding-left: 3%;">
          <div v-if="phase == '0'||phase == '4'">
            <el-radio @change="getRadio" v-model="radio" :label="'1'">采用数字摘要比对等方式对归档信息包的一致性进行检测。归档前计算归档信息包的数字摘要，接收时重新计算数字摘要并和归档前的数字摘要进行比对</el-radio>
          </div>
          <div v-if="phase == '1'">
            <el-radio @change="getRadio" v-model="radio" :label="'1'">采用数字摘要比对等方式对移交信息包的一致性进行检测。移交前计算移交信息包的数字摘要，接收时重新计算数字摘要并和移交前的数字摘要进行比对</el-radio>
          </div>
          <div v-if="phase == '2'">
            <el-radio @change="getRadio" v-model="radio" :label="'1'">采用数字摘要比对等方式对保存信息包的一致性进行检测。入库时计算并记录保存信息包的数字摘要，检测时重新计算数字摘要并和入库时生成的数字摘要进行比对</el-radio>
          </div>
        </div>
      </el-collapse-item>
    </div>

    <!-- 电子档案封装包规范性检测 -->
    <div v-if="item.dId == '1154' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1'">
        <template slot="title">
          <p style="width: 60%">检测项目: 电子档案封装包规范性检测</p>
          <p>检测对象: 电子档案封装包的结构</p>
        </template>
        <div style="padding-left: 3%;">
          <el-radio @change="getRadio" v-model="radio" :label="'1'">依据DA/T 48 2009的附录B《电子文件封装包的Schema》进行检测</el-radio>
        </div>
      </el-collapse-item>
    </div>

    <!-- 电子档案封装包电子签名有效性检测 -->
    <div v-if="item.dId == '1155' && item.isDetection != '0'" class="divBox">
      <el-collapse-item class="my-collapse-item" :disabled="item.isPass == '1' || Signature">
        <template slot="title">
          <p style="width: 60%">检测项目: 电子档案封装包电子签名有效性检测</p>
          <p>检测对象: 电子档案封装包电子签名有效性检测</p>
        </template>
        <div style="padding-left: 3%;">
          <el-radio @change="getRadio" v-model="radio" :label="'1'">读取封装包中的电子签名信息验证其有效性</el-radio>
        </div>
      </el-collapse-item>
    </div>
  </div>
</template>

<script>
import { getLastIndexOf } from "@/utils";
import {getDh, getSchemelist} from "@/api/archive/fourNatures/detectionPlan";

export default {
  name: "authenticity",
  props: ["item", "phase", "detail", "Packet", "Signature"],
  archive_Dicts: ['GHXX', 'YZXJC', 'YQYZXJC', 'SJLX', 'GSJC'],
  data() {
    return {
      selected: [],
      activeNames:'',

      // 元数据项数据长度检测
      activeLength: '',
      subStr: "",  //获取列表的 件 卷  项目 截取 sub_table_name显示
      folderOption: [],
      fileOption: [],
      folderRepeat: [],
      fileRepeat: [],
      folderSelected: [],
      fileSelected: [],

      folderCurrentPage: 1,
      folderPageSize: 10, // 每页显示的条目数
      folderPageNum: 1, // 当前页码
      folderTotal: 0,

      fileCurrentPage: 1,
      filePageSize: 10, // 每页显示的条目数
      filePageNum: 1, // 当前页码
      fileTotal: 0,

      // 下拉框
      firstSelected: {},
      secondSelected: {},
      thirdSelected: {},
      fourthSelected: {},

      // 输入框(数值,输入)
      firstSelect: [],
      secondSelect: [],
      firstInput: {},
      secondInput: {},
      // 页面数据
      params: {},
      isDisabled: true,

      juandh: '',
      jiandh: '',

      flag: false,

      radio: '',
      dataInfo: undefined
    }
  },
  watch: {
    detail: {
      handler(val) {
        if(val.subTableName != null) {
          this.subStr = getLastIndexOf(val.subTableName)
          if(this.subStr == 'V' || this.subStr == 'X') {
            this.getFolderOption()
            this.getFileOption()
            this.activeLength = 'first'
          } else {
            this.getFileOption()
            this.activeLength = 'second'
          }
        }
      },
      immediate: true,
      deep: true
    },
    item: {
      handler(val) {
        this.dataInfo = JSON.parse(JSON.stringify(val))
        this.getDataInfo()
        if(val.dId == '1111') {
          this.getSelected()
        }
      },
      deep: true,
      immediate: true
    },
    // 档号输入框监听
    'firstInput': {
      handler(newVal) {
        if(this.item.dId == '1126') {
          this.firstInput = newVal
          this.getChangeFirstInput()
        }
      },
      deep: true,
      immediate: true
    },
    'secondInput': {
      handler(newVal) {
        if(this.item.dId == '1126') {
          this.secondInput = newVal
          this.getChangeSecondInput()
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    tabClick() {
      console.log(this.firstInput, this.secondInput)
    },
    // 卷层输入框
    getChangeFirstInput() {
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        console.log(this.params)
        let params = JSON.parse(JSON.stringify(this.params))
        params.dId = this.item.dId
        params.isDetection = this.item.isDetection
        params.isPass = this.item.isPass
        if(this.item.dId == '1126') {
          params.detectionItemList = this.item.detectionItemList
        }
        params.detectionItemList = []
        var arr = params.detectionItemList
        for (let key in this.firstInput) {
          if (this.firstInput[key] != undefined) {
            var obj = {}
            obj.name = key
            obj.value = this.firstInput[key]
            obj.type = '1'
            obj.style = 'input' // 输入框
            arr.push(obj)
          }
        }
        for (let key in this.secondInput) {
          if(this.secondInput[key] != undefined) {
            var obj = {}
            obj.name = key
            obj.value = this.secondInput[key]
            obj.type = '0'
            obj.style = 'input' // 输入框
            arr.push(obj)
          }
        }
        params['detectionItemList'] = JSON.parse(JSON.stringify(arr))
        this.params = JSON.parse(JSON.stringify(params))
        console.log(this.firstInput, this.params.detectionItemList)
        this.$nextTick(() => {
          this.changeTap(params)
        })
      }
    },
    // 件输入框
    getChangeSecondInput() {
      console.log(this.secondInput)
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        let params = JSON.parse(JSON.stringify(this.params))
        params.dId = this.item.dId
        params.isDetection = this.item.isDetection
        params.isPass = this.item.isPass
        if(this.item.dId == '1126') {
          params.detectionItemList = this.item.detectionItemList
        }
        params.detectionItemList = []
        var arr = params.detectionItemList
        for (let key in this.firstInput) {
          if (this.firstInput[key] != undefined) {
            var obj = {}
            obj.name = key
            obj.value = this.firstInput[key]
            obj.type = '1'
            obj.style = 'input' // 输入框
            arr.push(obj)
          }
        }
        for (let key in this.secondInput) {
          if(this.secondInput[key] != undefined) {
            var obj = {}
            obj.name = key
            obj.value = this.secondInput[key]
            obj.type = '0'
            obj.style = 'input' // 输入框
            arr.push(obj)
          }
        }
        params['detectionItemList'] = JSON.parse(JSON.stringify(arr))
        this.params = JSON.parse(JSON.stringify(params))
        this.$nextTick(() => {
          this.changeTap(params)
        })
      }
    },
    // 卷下拉框
    getJuanSelected() {
      let result = {}
      // 处理第一个对象
      Object.entries(this.firstSelected).forEach(([key, item]) => {
        result[key] = {
          name: key,
          value: item,
          type: '1',
          style: 'select', // 下拉框
          price: null
        }
      })
      // 处理第二个对象
      Object.entries(this.secondSelected).forEach(([key, item]) => {
        if (this.firstSelected[key]) {
          result[key].price = item
        } else {
          result[key] = {
            name: key,
            value: null,
            type: '1',
            style: 'select', // 下拉框
            price: item
          }
        }
      })
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        let params = JSON.parse(JSON.stringify(this.params))
        params.dId = this.item.dId
        params.isDetection = this.item.isDetection
        params.isPass = this.item.isPass
        if (params.detectionItemList != null && params.detectionItemList != undefined) {
          if (params.detectionItemList.length != 0) {
            params.detectionItemList = JSON.parse(JSON.stringify(params.detectionItemList.filter(item => {
              return item.type != '1';
            })));
          }
        } else {
          params.detectionItemList = []
        }
        for (let key in result) {
          if (result[key] != undefined) {
            if(result[key].value != null || result[key].price != null) {
              params.detectionItemList.push(result[key])
            }
          }
        }
        this.$nextTick(() => {
          this.changeTap(params)
          this.params = JSON.parse(JSON.stringify(params))
        })
      }
    },
    // 件下拉框
    getJianSelected() {
      let result = {}
      // 处理第一个对象
      Object.entries(this.thirdSelected).forEach(([key, item]) => {
        result[key] = {
          name: key,
          value: item,
          type: '0',
          style: 'select', // 下拉框
          price: null
        }
      })
      // 处理第二个对象
      Object.entries(this.fourthSelected).forEach(([key, item]) => {
        if (this.thirdSelected[key]) {
          result[key].price = item
        } else {
          result[key] = {
            name: key,
            value: null,
            type: '0',
            style: 'select', // 下拉框
            price: item
          }
        }
      })
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        let params = JSON.parse(JSON.stringify(this.params))
        params.dId = this.item.dId
        params.isDetection = this.item.isDetection
        params.isPass = this.item.isPass
        if (params.detectionItemList != null && params.detectionItemList != undefined) {
          if (params.detectionItemList.length != 0) {
            params.detectionItemList = JSON.parse(JSON.stringify(params.detectionItemList.filter(item => {
              return item.type != '0';
            })));
          }
        } else {
          params.detectionItemList = []
        }
        for (let key in result) {
          if (result[key] != undefined) {
            if(result[key].value != null || result[key].price != null) {
              setTimeout(() => {
                params.detectionItemList.push(result[key])
              }, 0)
            }
          }
        }
        this.$nextTick(() => {
          this.changeTap(params)
          this.params = JSON.parse(JSON.stringify(params))
        })
      }
    },
    // 单选框
    getRadio() {
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        let params = JSON.parse(JSON.stringify(this.params))
        params.dId = this.item.dId
        params.isDetection = this.item.isDetection
        params.isPass = this.item.isPass
        params.detectionItemList = []
        var obj = {}
        obj.name = this.radio
        obj.style = 'radio' // 单选框
        setTimeout(() => {
          params.detectionItemList.push(obj)
        }, 0)
        this.$nextTick(() => {
          this.changeTap(params)
          this.params = JSON.parse(JSON.stringify(params))
        })
      }
    },
    // 多选框
    getSelected() {
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        if (this.item.dId == '1111') {
          // 勾选数字摘要
          var isPacket = null
          var isSignature = null
          if(this.selected.includes('1')) {
            this.activeNames = '1153'
            isPacket = false
            this.$emit("handleChangeGhxx",this.activeNames, isPacket)
          } else if(!this.selected.includes('1')) {
            this.activeNames = '1153'
            isPacket = true
            this.$emit("handleChangeGhxx",this.activeNames, isPacket)
          }
          // 勾选电子签名
          if(this.selected.includes('2')) {
            this.activeNames = '1155'
            isSignature = false
            this.$emit("handleChangeGhxx",this.activeNames, isPacket, isSignature)
          } else if(!this.selected.includes('2')) {
            this.activeNames = '1155'
            isSignature = true
            this.$emit("handleChangeGhxx",this.activeNames, isPacket, isSignature)
          }
        }
        this.params.dId = this.item.dId
        this.params.isDetection = this.item.isDetection
        this.params.isPass = this.item.isPass
        this.params.detectionItemList = []
        for (let i = 0; i < this.selected.length; i++) {
          var obj = {}
          obj.name = this.selected[i]
          obj.value = this.selected[i]
          obj.style = 'checkbox' // 多选框
          this.params.detectionItemList.push(obj)
        }
        this.$nextTick(() => {
          this.changeTap(this.params)
        })
      }
    },
    // 卷多选框
    getFolderSelected() {
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        let params = JSON.parse(JSON.stringify(this.params))
        params.dId = this.item.dId
        params.isDetection = this.item.isDetection
        params.isPass = this.item.isPass
        if (params.detectionItemList != null && params.detectionItemList != undefined) {
          if (params.detectionItemList.length != 0) {
            params.detectionItemList = JSON.parse(JSON.stringify(params.detectionItemList.filter(item => {
              return item.type != '1';
            })));
          }
        } else {
          params.detectionItemList = []
        }
        var arr = params.detectionItemList
        for (let i = 0; i < this.folderSelected.length; i++) {
          var obj = {}
          obj.name = this.folderSelected[i]
          obj.type = '1'
          obj.style = 'check' // 多选框
          arr.push(obj)
        }
        params['detectionItemList'] = JSON.parse(JSON.stringify(arr))
        this.$nextTick(() => {
          this.changeTap(params)
          this.params = JSON.parse(JSON.stringify(params))
        })
      }
    },
    // 件多选框
    getFileSelected() {
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        let params = JSON.parse(JSON.stringify(this.params))
        params.dId = this.item.dId
        params.isDetection = this.item.isDetection
        params.isPass = this.item.isPass
        if (params.detectionItemList != null && params.detectionItemList != undefined) {
          if (params.detectionItemList.length != 0) {
            params.detectionItemList = JSON.parse(JSON.stringify(params.detectionItemList.filter(item => {
              return item.type != '0';
            })));
          }
        } else {
          params.detectionItemList = []
        }
        var arr = params.detectionItemList
        for (let i = 0; i < this.fileSelected.length; i++) {
          var obj = {}
          obj.name = this.fileSelected[i]
          obj.type = '0'
          obj.style = 'check' // 多选框
          arr.push(obj)
        }
        params['detectionItemList'] = JSON.parse(JSON.stringify(arr))
        this.$nextTick(() => {
          this.changeTap(params)
          this.params = JSON.parse(JSON.stringify(params))
        })
      }
    },
    // 回显数据
    getDataInfo() {
      if (this.dataInfo.detectionItemList != null) {
        if (this.dataInfo.detectionItemList.length != 0) {
          for (let i = 0; i < this.dataInfo.detectionItemList.length; i++) {
            if (this.dataInfo.detectionItemList[i].style == 'checkbox') {
              this.selected.push(this.dataInfo.detectionItemList[i].name);
            }
            this.selected = [...this.selected]

            if (this.dataInfo.detectionItemList[i].style == 'check') {
              if (this.dataInfo.detectionItemList[i].type == '1') {
                this.folderSelected.push(this.dataInfo.detectionItemList[i].name)
              } else if (this.dataInfo.detectionItemList[i].type == '0') {
                this.fileSelected.push(this.dataInfo.detectionItemList[i].name)
              }
            }
            this.folderSelected = [...this.folderSelected]
            this.fileSelected = [...this.fileSelected]

            if (this.dataInfo.detectionItemList[i].style == 'select') {
              if (this.dataInfo.detectionItemList[i].type == '1') {
                this.firstSelect.push(this.dataInfo.detectionItemList[i].name)
                this.$set(this.firstSelected, this.dataInfo.detectionItemList[i].name, this.dataInfo.detectionItemList[i].value);
                this.$set(this.secondSelected, this.dataInfo.detectionItemList[i].name, this.dataInfo.detectionItemList[i].price);
              } else if (this.dataInfo.detectionItemList[i].type == '0') {
                this.secondSelect.push(this.dataInfo.detectionItemList[i].name)
                this.$set(this.thirdSelected, this.dataInfo.detectionItemList[i].name, this.dataInfo.detectionItemList[i].value);
                this.$set(this.fourthSelected, this.dataInfo.detectionItemList[i].name, this.dataInfo.detectionItemList[i].price);
              }
            }
            this.firstSelect = [...this.firstSelect]
            this.secondSelect = [...this.secondSelect]

            if (this.dataInfo.detectionItemList[i].style == 'input') {
              if (this.dataInfo.detectionItemList[i].type == '1') {
                if (this.firstSelect.findIndex(item => item == this.dataInfo.detectionItemList[i].name) < 0) {
                  this.firstSelect.push(this.dataInfo.detectionItemList[i].name)
                  this.$set(this.firstInput, this.dataInfo.detectionItemList[i].name, this.dataInfo.detectionItemList[i].value);
                }
              } else if (this.dataInfo.detectionItemList[i].type == '0') {
                if (this.secondSelect.findIndex(item => item == this.dataInfo.detectionItemList[i].name) < 0) {
                  this.secondSelect.push(this.dataInfo.detectionItemList[i].name)
                  this.$set(this.secondInput, this.dataInfo.detectionItemList[i].name, this.dataInfo.detectionItemList[i].value);
                }
              }
            }
            this.firstSelect = [...this.firstSelect]
            this.secondSelect = [...this.secondSelect]

            if (this.dataInfo.detectionItemList[i].style == 'radio') {
              this.$set(this, 'radio', this.dataInfo.detectionItemList[i].name);
            }
          }
        }
      }
    },
    changeTap(item) {
      this.$emit('ChangeTap', item)
    },
    getRef(val, isDisabled){
      if(isDisabled != undefined) {
        this.item.isDisabled = isDisabled
      }
    },
    handleChange(parent, item, index) {
      console.log(item)
      if(item.editable == false) {
        item.editable = true
      } else {
        item.editable = false
      }
      if(parent.dId == '1126') {
        if(item.type == '1') {
          item.editable = false
          this.$set(this.firstInput, item.id, this.juandh)
          this.changeInput()
        } else {
          item.editable = false
          this.$set(this.secondInput, item.id, this.jiandh)
          this.changeInput()
        }
      }
      if(item.type == '1') {
        if (this.firstSelect.indexOf(item.id) == -1) {
          // 未勾选
          this.firstInput[item.id] = undefined; // 清空输入值
          this.firstSelected[item.id] = undefined
          this.secondSelected[item.id] = undefined
          this.changeInput()
          this.changeSelected()
        }
      } else {
        if (this.secondSelect.indexOf(item.id) == -1) {
          // 未勾选
          this.secondInput[item.id] = undefined; // 清空输入值
          this.thirdSelected[item.id] = undefined
          this.fourthSelected[item.id] = undefined
          this.changeInput()
          this.changeSelected()
        }
      }
      // if(item.editable == false) {
      //   this.firstSelected[item.id] = undefined
      //   this.secondSelected[item.id] = undefined
      //   this.thirdSelected[item.id] = undefined
      //   this.fourthSelected[item.id] = undefined
      //   this.changeJuanSelected()
      //   this.changeJianSelected()
      // }
    },
    // 针对禁用时对输入框的数据处理
    changeInput() {
      let params = JSON.parse(JSON.stringify(this.params))
      params.dId = this.item.dId
      params.isDetection = this.item.isDetection
      params.isPass = this.item.isPass
      params.detectionItemList = []
      var arr = params.detectionItemList
      for (let key in this.firstInput) {
        if(this.firstInput[key] != undefined) {
          var obj = {}
          obj.name = key
          obj.value = this.firstInput[key]
          obj.type = '1'
          obj.style = 'input' // 输入框
          arr.push(obj)
        }
      }
      for (let key in this.secondInput) {
        if(this.secondInput[key] != undefined) {
          var obj = {}
          obj.name = key
          obj.value = this.secondInput[key]
          obj.type = '0'
          obj.style = 'input' // 输入框
          arr.push(obj)
        }
      }
      params['detectionItemList'] = JSON.parse(JSON.stringify(arr))
      this.params = JSON.parse(JSON.stringify(params))
      this.$nextTick(() => {
        this.changeTap(params)
      })
    },
    // 针对禁用时对下拉框的数据处理
    changeSelected() {
      let result = {}
      // 处理第一个对象
      Object.entries(this.firstSelected).forEach(([key, item]) => {
        result[key] = {
          name: key,
          value: item,
          type: '1',
          style: 'select', // 下拉框
          price: null
        }
      })
      // 处理第二个对象
      Object.entries(this.secondSelected).forEach(([key, item]) => {
        if (this.firstSelected[key]) {
          result[key].price = item
        } else {
          result[key] = {
            name: key,
            value: null,
            type: '1',
            style: 'select', // 下拉框
            price: item
          }
        }
      })
      let result1 = {}
      // 处理第一个对象
      Object.entries(this.thirdSelected).forEach(([key, item]) => {
        result1[key] = {
          name: key,
          value: item,
          type: '0',
          style: 'select', // 下拉框
          price: null
        }
      })
      // 处理第二个对象
      Object.entries(this.fourthSelected).forEach(([key, item]) => {
        if (this.thirdSelected[key]) {
          result1[key].price = item
        } else {
          result1[key] = {
            name: key,
            value: null,
            type: '0',
            style: 'select', // 下拉框
            price: item
          }
        }
      })
      if(this.item.isPass == 0 && this.item.isDetection == 1) {
        let params = JSON.parse(JSON.stringify(this.params))
        params.dId = this.item.dId
        params.isDetection = this.item.isDetection
        params.isPass = this.item.isPass
        params.detectionItemList = []
        for (let key in result) {
          if (result[key] != undefined) {
            if(result[key].value != null || result[key].price != null) {
              params.detectionItemList.push(result[key])
            }
          }
        }
        for (let key in result1) {
          if (result1[key] != undefined) {
            if(result1[key].value != null || result1[key].price != null) {
              setTimeout(() => {
                params.detectionItemList.push(result1[key])
              }, 0)
            }
          }
        }
        this.$nextTick(() => {
          this.changeTap(params)
          this.params = JSON.parse(JSON.stringify(params))
        })
      }
    },
    // 获取卷元数据
    getFolderOption() {
      if(this.item.dId == '1127') {
        this.form = {
          categoryId: this.detail.categoryId,
          isMetadata: 1,
          type: 1,
          repeatString: 0,
          pageNum: this.folderPageNum,
          pageSize: this.folderPageSize
        }
        this.getRepeat(this.form)
      } else if(this.item.dId == '1121' || this.item.dId == '1122' || this.item.dId == '1123' || this.item.dId == '1124' || this.item.dId == '1125') {
        this.form = {
          categoryId: this.detail.categoryId,
          isMetadata: 1,
          type: 1,
          pageNum: this.folderPageNum,
          pageSize: this.folderPageSize
        }
        this.getMetaData(this.form)
      } else if (this.item.dId == '1126') {
        this.form = {
          categoryId: this.detail.categoryId,
          isMetadata: 1,
          type: 1,
          isArchiveNo: 1,
          pageNum: this.folderPageNum,
          pageSize: this.folderPageSize
        }
        this.getMetaData(this.form, '1126')
        this.getRule('v')
      }
    },
    // 获取件元数据
    getFileOption() {
      if(this.item.dId == '1127') {
        this.form = {
          categoryId: this.detail.categoryId,
          isMetadata: 1,
          type: 0,
          repeatString: 0,
          pageNum: this.filePageNum,
          pageSize: this.filePageSize
        }
        this.getRepeat(this.form)
      } else if(this.item.dId == '1121' || this.item.dId == '1122' || this.item.dId == '1123' || this.item.dId == '1124' || this.item.dId == '1125') {
        this.form = {
          categoryId: this.detail.categoryId,
          isMetadata: 1,
          type: 0,
          pageNum: this.filePageNum,
          pageSize: this.filePageSize
        }
        this.getMetaData(this.form)
      } else if (this.item.dId == '1126') {
        this.form = {
          categoryId: this.detail.categoryId,
          isMetadata: 1,
          type: 0,
          isArchiveNo: 1,
          pageNum: this.folderPageNum,
          pageSize: this.folderPageSize
        }
        this.getMetaData(this.form, '1126')
        this.getRule('f')
      }
    },
    // 卷分页
    handleFolderPageChange(currentPage) {
      this.folderPageNum = currentPage;
      this.getFolderOption()
    },
    // 件分页
    handleFilePageChange(currentPage) {
      this.filePageNum = currentPage
      this.getFileOption()
    },
    // 正常元数据
    getMetaData(form, dId) {
      getSchemelist(form).then(response=>{
        if(form.type == '1') {
          this.folderOption = []
          this.folderOption = response.rows.map(item=>{
            return {
              id: item.id,
              label: item.fieldCaption,
              editable: false,
              type: '1'
            }
          })
          for (let i = 0; i < this.firstSelect.length; i++) {
            this.folderOption.forEach((item) => {
              if (item.id == this.firstSelect[i]) {
                item.editable = true;
              }
            });
          }
          this.folderTotal = response.total
        } else {
          this.fileOption = []
          this.fileOption = response.rows.map(item=>{
            return {
              id: item.id,
              label: item.fieldCaption,
              editable: false,
              type: '0'
            }
          })
          for (let i = 0; i < this.secondSelect.length; i++) {
            this.fileOption.forEach((item) => {
              if (item.id == this.secondSelect[i]) {
                item.editable = true;
              }
            });
          }
          this.fileTotal = response.total
        }
      })
    },
    // 可重复性
    getRepeat(form) {
      getSchemelist(form).then(response=>{
        if(form.type == '1') {
          this.folderRepeat = []
          this.folderRepeat = response.rows.map(item=>{
            return {
              id: item.id,
              label: item.fieldCaption,
              editable: false,
              type: '1'
            }
          })
          for (let i = 0; i < this.fileSelected.length; i++) {
            this.folderRepeat.forEach((item) => {
              if (item.id == this.fileSelected[i]) {
                item.editable = true;
              }
            });
          }
          this.folderTotal = response.total
        } else {
          this.fileRepeat = []
          this.fileRepeat = response.rows.map(item=>{
            return {
              id: item.id,
              label: item.fieldCaption,
              editable: false,
              type: '0'
            }
          })
          for (let i = 0; i < this.fileSelected.length; i++) {
            this.fileRepeat.forEach((item) => {
              if (item.id == this.fileSelected[i]) {
                item.editable = true;
              }
            });
          }
          this.fileTotal = response.total
        }
      })
    },
    getRule(type) {
      this.form = {
        categoryId: this.detail.categoryId,
        type: type,
      }
      getDh(this.form).then(response=>{
        this.juandh = response.data[0].juandh
        this.jiandh = response.data[0].jiandh
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.my-collapse-item::after {
  content: "";
  display: block;
  border-bottom: 1px solid #ebeef5; /* 下边界线样式 */
}
.my-collapse-item {
  width: 100%;
}

.divBox {
  display: flex;
}

.checkBox {
  flex-basis: 40%;
  margin-bottom: 1%;
  .el-checkbox {
    width: 30%;
  }
  .el-select {
    width: 33%;
    margin: 1%
  }
  .el-input {
    width: 50%
  }
}
</style>
